#include "progressbar.h"
#include "sysinfo.h"
#include <unistd.h>

ProgressBar::ProgressBar(QWidget *parent) :
    QProgressBar(parent)
{
    this->setCursor(Qt::PointingHandCursor);
}

void ProgressBar::mouseDoubleClickEvent(QMouseEvent *)
{
    /* We Cached the start_value */
    int start_value = this->value();

    /* Drop Mem , Then We got Value */
    if(system("echo 3 > /proc/sys/vm/drop_caches") == -1 ) {
        qDebug("Error for Drop Cache\n");
    }

    int end_value = (int)(((SysInfo *)this->parent())->read_mem() * 100);

    /* repainter This */
    repainter_chunk(start_value, end_value);
}

void ProgressBar::repainter_chunk(int start_value, int end_value)
{
    /* First, We dec it to zero */
    while(start_value --) {
        this->setValue(start_value);
        usleep(8000);
    }

    /* And , We Add it to End_value */
    while(start_value ++ < end_value) {
        this->setValue(start_value);
        usleep(8000);
    }
}
